home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 452 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.7 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: gusty@clark.net (Harlan Messinger)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: typedef not strong
  5. Date: 22 Feb 1996 21:33:36 GMT
  6. Organization: Clark Internet Services, Inc., Ellicott City, MD USA
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4gimon$317@clarknet.clark.net>
  9. References: <4g5sm4$dtt@natasha.rmii.com> <4g8vdo$igt@mulga.cs.mu.OZ.AU>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Mime-Version: 1.0
  12. Content-Type: TEXT/PLAIN; charset="ISO-8859-1"
  13. Content-Transfer-Encoding: 8bit
  14. X-Nntp-Posting-Host: explorer.clark.net
  15. X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
  16. X-Lines: 42
  17. Content-Length: 1743
  18. Originator: clamage@taumet
  19.  
  20. Fergus Henderson (fjh@munta.cs.mu.OZ.AU) wrote:
  21. : rpayne@rainbow.rmii.com (Robert Payne) writes:
  22. : >Why has C++ stayed with the weak typedef?  It has always seemed to
  23. : >me that it should provide a new type and not just a synomym.  Some
  24. : >lints check for strong typing but I haven't found a compiler that 
  25. : >will enforce it.  I know this must have been debated at some point
  26. : >but I didn't find it in a FAQ.  Could someone please enlighten me?
  27. : If typedef were to create a new type, what operations would be allowed
  28. : on the new type?
  29. : I think that changing the meaning of `typedef' would be a bad idea.
  30. : It might make sense to propose a new construct, say `newtypedef', that
  31. : did something different, but C++ already has a way to create new types
  32. : (`class'), and it is not at all clear that adding a new way would be
  33. : worth the additional complexity.
  34.  
  35.  
  36. I see two issues at odds here, and a desire to satisfy them both with one 
  37. construct.
  38.  
  39. One issue is type safety in function calls. You might have
  40.  
  41.     typedef double DOLLARS;
  42.     typedef double INTEREST_RATE;
  43.  
  44. and want to define a function declared as
  45.  
  46.     DOLLARS PresentValue(DOLLARS futureValue, 
  47.         INTEREST_RATE rate, int YEARS);
  48.  
  49. that will keep the user from accidentally swapping the money and interest 
  50. arguments when coding a call to the function.
  51.  
  52. On the other hand, within functions that use these types, you might want
  53. all the ordinary mathematical functions to apply as usual to the raw
  54. values underneath. The function call has already guaranteed that the set
  55. of arguments given has types that are meaningful given the function's 
  56. purpose. Now we want to take these arguments for what they really 
  57. are--doubles--and apply normal arithmetic to them with no headaches.
  58.  
  59.  
  60. [ To submit articles: Try just posting with your newsreader.
  61.               If that fails, use mailto:std-c++@ncar.ucar.edu
  62.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  63.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  64.   Comments? mailto:std-c++-request@ncar.ucar.edu
  65. ]
  66.